package com.aidex.baseinfo.controller;

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.framework.cache.DictUtils;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.baseinfo.domain.BaseWarehouse;
import com.aidex.baseinfo.service.BaseWarehouseService;

/**
 * 仓库信息Controller
 * @author cq
 * @email 382425530@qq.com
 * @date 2023-06-21
 */
@RestController
@RequestMapping("/baseinfo/baseWarehouse")
public class BaseWarehouseController extends BaseController {

    @Autowired
    private BaseWarehouseService baseWarehouseService;

    /**
     * 查询仓库信息列表
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:baseWarehouse:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BaseWarehouse baseWarehouse, HttpServletRequest request, HttpServletResponse response) {
        baseWarehouse.setPage(new PageDomain(request, response));
        return R.data(baseWarehouseService.findPage(baseWarehouse));
    }

    /**
     * 获取仓库信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:baseWarehouse:query')")
    @GetMapping(value = "/{id}")
    public R<BaseWarehouse> detail(@PathVariable("id") String id) {
        return R.data(baseWarehouseService.get(id));
    }

    /**
     * 新增仓库信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:baseWarehouse:add')")
    @Log(title = "仓库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BaseWarehouse baseWarehouse) {
        return R.status(baseWarehouseService.save(baseWarehouse));
    }

    /**
     * 修改仓库信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:baseWarehouse:edit')")
    @Log(title = "仓库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BaseWarehouse baseWarehouse) {
        return R.status(baseWarehouseService.save(baseWarehouse));
    }

    /**
     * 删除仓库信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:baseWarehouse:remove')")
    @Log(title = "仓库信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(baseWarehouseService.deleteBaseWarehouseByIds(ids));
    }


    /**
     * 导出仓库信息列表
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:baseWarehouse:export')")
    @Log(title = "仓库信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BaseWarehouse baseWarehouse) {
        List<BaseWarehouse> list = baseWarehouseService.findList(baseWarehouse);
        ExcelUtil<BaseWarehouse> util = new ExcelUtil<BaseWarehouse>(BaseWarehouse.class);
        return util.exportExcel(list, "仓库信息数据");
    }
	
    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

}
